<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #slide {
      position: relative;
      width: 600px;
      height: 30px;
      margin: 100px auto;
      border: 1px solid #000;
    }

    #block {
      position: absolute;
      left: 0;
      top: 0;
      width: 30px;
      height: 30px;
      background-color: blue;
    }

    #full {
      position: absolute;
      left: 0;
      top: 0;
      width: 0;
      height: 30px;
      background-color: orange;
    }
  </style>
</head>

<body>
  <div id="slide">
    <div id="full"></div>
    <div id="block"></div>
  </div>
  <script>
    var oSlide = document.getElementById("slide")
    var oBlock = document.getElementById("block")
    var oFull = document.getElementById("full")

    if (!window.localStorage) {
      alert("该浏览器不支持localStorage")
    } else {
      var l = localStorage.slide
      oBlock.style.left = l + "px"
      oFull.style.width = l + "px"
    }

    oBlock.onmousedown = function (ev) {
      var e = ev || window.event
      var offsetX = e.clientX - oBlock.offsetLeft
      document.onmousemove = function (ev) {
        var e = ev || window.event
        var l = e.clientX - offsetX
        if (l <= 0) {
          l = 0
        }
        if (l >= 570) {
          l = 570
        }
        oBlock.style.left = l + "px"

        oFull.style.width = l + "px"

        if (!window.localStorage) {
          alert("该浏览器不支持localStorage")
        } else {
          localStorage.slide = l
        }
      }
    }

    document.onmouseup = function () {
      document.onmousemove = null
    }
  </script>
</body>

</html>